const app = getApp()

const formatTime = date => {
  const year = date.getFullYear()
  const month = date.getMonth() + 1
  const day = date.getDate()
  const hour = date.getHours()
  const minute = date.getMinutes()
  const second = date.getSeconds()

  return [year, month, day].map(formatNumber).join('-') + ' ' + [hour, minute, second].map(formatNumber).join(':')
}

 
const formatNumber = n => {
  n = n.toString()
  return n[1] ? n : '0' + n
}

// function getOpenid() {
//   // 调用云函数
//   wx.cloud.callFunction({
//     name: 'login',
//     data: {},
//     success: res => {
//       let openid = res.result.openid
//       console.log('[云函数] [login] user openid: ', openid)
//       app.globalData.openid = openid
//       return openid
//     },
//     fail: err => {
//       console.error('[云函数] [login] 调用失败', err)
//       return null
//     }
//   })
// }


module.exports = {
  formatTime: formatTime,
}